package com.iflytek.crvoice2txt.util;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;

import static android.content.Context.NOTIFICATION_SERVICE;

public class NotificationUtil {

    private int notificationCounter;// 一个用于计算通知多少的计数器。
    private NotificationManager notificationManager;

    public NotificationUtil(Context context) {
        notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
    }

    public void sendNotification(BaseNotification baseNotification) {

        if (notificationManager == null || baseNotification == null) {
            return;
        }
        notificationCounter++;
        Notification notification = new Notification();
        notification.iconLevel = baseNotification.resId;
        notification.flags = baseNotification.isAutoHide;
        notification.tickerText = baseNotification.text;
        notification.when = baseNotification.sendTime;
        notification.defaults = baseNotification.defaultAll;
        // 以下三行为：在MainActivity中，如果点击信息则，打开Activity1
        //Intent intent = new Intent(MainActivity.this, Activity1.class);
        //PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);
        //notification.setLatestEventInfo(MainActivity.this, "消息标题", "消息内容", pendingIntent);
        // 要求通知管理器发送这条通知，其中第一个参数是通知在系统的id
        notificationManager.notify(notificationCounter, notification);
    }


    class BaseNotification {
        int resId;
        int isAutoHide;
        String text;
        long sendTime;
        int defaultAll;

        public BaseNotification() {
        }

        public BaseNotification(int resId, int isAutoHide, String text, long sendTime, int defaultAll) {
            this.resId = resId;
            this.isAutoHide = isAutoHide;
            this.text = text;
            this.sendTime = sendTime;
            this.defaultAll = defaultAll;
        }
    }

}
